home *** CD-ROM | disk | FTP | other *** search
/ Euroscene 2 / Euroscene 2.iso / USEFUL / DeliTracker130 / Developer / Developer.run / Examples / DSS.s < prev    next >
Encoding:
Text File  |  1992-09-23  |  21.4 KB  |  817 lines

  1.  
  2.     incdir    "Includes:"
  3.     include    "misc/DeliPlayer.i"
  4.  
  5. ;
  6. ;
  7.     SECTION Player,Code
  8. ;
  9. ;
  10.  
  11.     PLAYERHEADER PlayerTagArray
  12.  
  13.     dc.b '$VER: Digital Sound Studio 1.15 player module V1.1 (14 Aug 92)',0
  14.     even
  15.  
  16. PlayerTagArray
  17.     dc.l    DTP_PlayerVersion,0
  18.     dc.l    DTP_PlayerName,PName
  19.     dc.l    DTP_Creator,CName
  20.     dc.l    DTP_Check2,Chk
  21.     dc.l    DTP_Interrupt,Int
  22.     dc.l    DTP_InitPlayer,InitPlayer
  23.     dc.l    DTP_EndPlayer,EndPlayer
  24.     dc.l    DTP_InitSound,InitSnd
  25.     dc.l    DTP_EndSound,RemSnd
  26.     dc.l    TAG_DONE
  27.  
  28. *-----------------------------------------------------------------------*
  29. ;
  30. ; Player/Creatorname und lokale Daten
  31.  
  32. PName    dc.b 'DSS',0
  33. CName    dc.b 'CIS, © by GVP 1991,',10
  34.     dc.b 'adapted by Delirium',0
  35.     even
  36.  
  37. *-----------------------------------------------------------------------*
  38. ;
  39. ;Interrupt für Replay
  40.  
  41. Int
  42.     movem.l    d0-d7/a0-a6,-(sp)
  43.     jsr    PlayRoutine             ; DudelDiDum
  44.     movem.l    (sp)+,d0-d7/a0-a6
  45.     rts
  46.  
  47. *-----------------------------------------------------------------------*
  48. ;
  49. ; Testet auf Modul
  50.  
  51. Chk    move.l    dtg_ChkData(a5),a0        ; Check DSS Module
  52.     cmpi.l    #"MMU2",(a0)            ; Is it DSS at all ?
  53.     bne.s    ChkFail                ; No!
  54.  
  55.     lea    sng_Len(a0),a1            ; Yes, the the next question
  56.     move.w    (a1)+,d0            ; is: is this just a DSS song
  57.     subq.w    #1,d0                ; or really a playable module?
  58.     moveq    #0,d1                ; The only difference between
  59.     move.l    d1,d2                ; a DSS module and a DSS song
  60. Chk_Loop                    ; is that the module includes
  61.     move.b    (a1)+,d1            ; the samples at the end of the
  62.     cmp.b    d1,d2                ; songdata. So we calculate the
  63.     bhi.s    Chk_NotLast            ; end of the songdata and check
  64.     move.b    d1,d2                ; if it is not the end of the
  65. Chk_NotLast                    ; loaded file! if so the file
  66.     dbra    d0,Chk_Loop            ; includes the samples and is
  67.     addq.w    #1,d2                ; playable.
  68.     moveq    #10,d0
  69.     lsl.l    d0,d2                ; size * 1024 (blocksize)
  70.     add.l    #sng_Data,d2            ; first sample
  71.     lea    sng_Instr0(a0),a1        ; first instrument
  72.     moveq    #MAXINSTR,d0
  73. Chk_AdrLoop
  74.     moveq    #0,d1
  75.     move.w    instr_Len(a1),d1        ; len
  76.     beq.s    Chk_NextAdr
  77.     add.l    d1,d1
  78. Chk_ThisAdr
  79.     add.l    d1,d2
  80.     moveq    #0,d1
  81.     cmp.w    #1,instr_RLen(a1)        ; rlen
  82.     beq.s    Chk_SampleSize
  83.     move.w    instr_RLen(a1),d1
  84.     add.l    d1,d1
  85. Chk_SampleSize
  86.     add.l    d1,d2
  87.     bclr    #0,instr_Start+3(a1)        ; align instr_Start on a word
  88.     add.l    instr_Start(a1),d2        ; Start
  89. Chk_NextAdr
  90.     lea    SIZEOF_insdt(a1),a1
  91.     dbra    d0,Chk_AdrLoop
  92.  
  93.     sub.l    dtg_ChkSize(a5),d2        ; test size of file
  94.     cmpi.l    #-64,d2                ; - 64 Bytes
  95.     blt.s    ChkFail                ; too small
  96.     cmpi.l    #+64,d2                ; + 64 Bytes
  97.     bgt.s    ChkFail                ; too big
  98.  
  99.     moveq    #0,d0                ; Modul erkannt
  100.     bra.s    ChkEnd
  101. ChkFail
  102.     moveq    #-1,d0                ; Modul nicht erkannt
  103. ChkEnd
  104.     rts
  105.  
  106. *-----------------------------------------------------------------------*
  107. ;
  108. ; Init Player
  109.  
  110. InitPlayer
  111.     moveq    #0,d0
  112.     move.l    dtg_GetListData(a5),a0        ; Function
  113.     jsr    (a0)
  114.     move.l    a0,SongPointer
  115.  
  116.     move.l    dtg_AudioAlloc(a5),a0        ; Function
  117.     jsr    (a0)                ; returncode is already set !
  118.     rts
  119.  
  120. *-----------------------------------------------------------------------*
  121. ;
  122. ; End Player
  123.  
  124. EndPlayer
  125.     move.l    dtg_AudioFree(a5),a0        ; Function
  126.     jsr    (a0)
  127.     rts
  128.  
  129. *-----------------------------------------------------------------------*
  130. ;
  131. ; Init Sound
  132.  
  133. InitSnd
  134.     jsr    InitSampleAdr
  135.     jsr    InitSamples
  136.     jsr    EnablePlayer
  137.  
  138.     clr.w    PlayOn            ; additional cleanup
  139.     clr.w    PlayTimer
  140.     clr.w    CurrentPos
  141.     clr.l    OffsetBlock
  142.     clr.w    AudioDMA
  143.     clr.w    MasterVolume
  144.     clr.w    BreakStatus
  145.     clr.w    NewPosJump
  146.     rts
  147.  
  148. *-----------------------------------------------------------------------*
  149. ;
  150. ; Rem Sound
  151.  
  152. RemSnd
  153.     jsr    DisablePlayer
  154.     rts
  155.  
  156. *-----------------------------------------------------------------------*
  157. ;
  158. ;**************************************************************************
  159. ;*
  160. ;*   DSS MODULE PLAY ROUTINE
  161. ;*   -----------------------
  162. ;*
  163. ;*   If you wish to use some DSS Tracker Modules into your own programs,
  164. ;*   you can read the following listing...
  165. ;*
  166. ;*   This file contains the needed functions for playing a DSS Module.
  167. ;*   You have to allocate, to load  and to free the memory (CHIP) yourself.
  168. ;*
  169. ;*  >Once the Module is loaded in CHIP memory:
  170. ;*
  171. ;*   -Set the [ SongPointer ] pointer (at the end of this file) with the
  172. ;*    Module's address.
  173. ;*   -Call the [ InitPlay() ] function.
  174. ;*
  175. ;*  >To stop the Module, you just have to call the [ RemovePlayer() ]
  176. ;*   function.
  177. ;*
  178. ;*   This program has been writen for the Aztec C 3.6 assembler.
  179. ;*   It can be easily adapted to another assembler.
  180. ;*
  181. ;**************************************************************************
  182.  
  183. ;----- Amiga function ------
  184.  
  185. _LVOOpenResource        EQU        -498
  186. _LVOAddICRVector        EQU        -6
  187. _LVORemICRVector        EQU        -12
  188.  
  189. ;------- ExecBase ----
  190.  
  191. SysBase                 EQU     4
  192. PAL                     EQU     50
  193. eb_PowerSupplyFreq      EQU     531
  194.  
  195. ;------- CIAA --------
  196.  
  197. CIAAPRA         EQU     $bfe001
  198. CIABTALO        EQU     $bfd400
  199. CIABTAHI        EQU     $bfd500
  200. CIABICR         EQU     $bfdd00
  201. CIABCRA         EQU     $bfde00
  202.  
  203. CIABTBLO        EQU     $bfd600
  204. CIABTBHI        EQU     $bfd700
  205. CIABCRB         EQU     $bfdf00
  206.  
  207. ;------ Song ----------
  208.  
  209. sng_Tempo       EQU     8
  210. sng_Instr0      EQU     10
  211. sng_Len         EQU     1436
  212. sng_Seq         EQU     1438
  213. sng_Data        EQU     1566
  214.  
  215. ;------ InstrData -----
  216.  
  217. MAXINSTR        EQU     30
  218. SIZEOF_insdt    EQU     46
  219.  
  220. instr_Name      EQU     0
  221. instr_Start     EQU     30
  222. instr_Len       EQU     34
  223. instr_RStart    EQU     36
  224. instr_RLen      EQU     40
  225. instr_Vol       EQU     42
  226. instr_Freq      EQU     44
  227.  
  228. ;------- AudioData -
  229.  
  230. SIZEOF_ad       EQU     24
  231.  
  232. ad_SampPer      EQU     0
  233. ad_Effet        EQU     2
  234. ad_Info         EQU     3
  235. ad_Volume       EQU     4
  236. ad_SmpAdr       EQU     6
  237. ad_SmpLen       EQU     10
  238. ad_RepAdr       EQU     12
  239. ad_RepLen       EQU     16
  240. ad_ArpPer       EQU     18
  241. ad_DMABit       EQU     20
  242. ad_PitchPer     EQU     22
  243.  
  244. ;------- AudioChips -------
  245.  
  246. DMACON          EQU     $dff096
  247. DMASET          EQU     $8000
  248.  
  249. AUD0LCH         EQU     $dff0a0
  250. AUD1LCH         EQU     $dff0b0
  251. AUD2LCH         EQU     $dff0c0
  252. AUD3LCH         EQU     $dff0d0
  253. AUDxLEN         EQU     $4
  254. AUDxPER         EQU     $6
  255. AUDxVOL         EQU     $8
  256. AUDxDAT         EQU     $a
  257. SIZEOF_AUD      EQU     $10
  258.  
  259. ;------ Block ---------
  260.  
  261. NEXTTRACK       EQU     4
  262. NEXTLINE        EQU     16
  263. BLOCKSIZE       EQU     1024
  264. MAXTRACK        EQU     4
  265.  
  266. ;------- Notes -------
  267.  
  268. DO2             EQU     1712
  269. SI5             EQU     113
  270. STOP            EQU     $7ff
  271.  
  272. ;------- Effects -----
  273.  
  274. MASK_EFF        EQU     7
  275. MASK_VAL        EQU     $f
  276.  
  277. ARPEGGIO        EQU     0
  278. PITCHUP         EQU     1
  279. PITCHDOWN       EQU     2
  280. VOLUME          EQU     3
  281. MASTERVOL       EQU     4
  282. TEMPO           EQU     5
  283. JUMP            EQU     6
  284. FILTER          EQU     7
  285.  
  286. MAX_VOL         EQU     64
  287. BREAK           EQU     $ff
  288.  
  289.  
  290.         CSEG
  291.  
  292. ;------------------ functions to call -----------------
  293.  
  294. ; Timer interruption installation and Player initialization routines
  295. ; Return 0 (zero) if successful.
  296. ; Return 1 if the installation is not possible.
  297.  
  298. ;InitPlay:
  299. ;        movem.l d1-d2/a0-a3/a6,-(sp)
  300. ;        move.l  SysBase,a6
  301. ;        lea     CiabName,a1
  302. ;        moveq   #0,d0
  303. ;        jsr     _LVOOpenResource(a6)
  304. ;        move.l  d0,CiabBase
  305. ;        beq.s   InitPlayError
  306. ;        cmp.b   #PAL,eb_PowerSupplyFreq(a6)
  307. ;        beq.s   initsong
  308. ;        move.w  #2,IsNTSC
  309. ;initsong:
  310. ;        bsr.s   InitSampleAdr
  311. ;        bsr.s   InitSamples
  312. ;        bsr.s   InitInterrupt
  313. ;        tst.l   d0
  314. ;        beq.s   EndInitPlay
  315. ;InitPlayError:
  316. ;        moveq   #1,d0
  317. ;EndInitPlay:
  318. ;        movem.l (sp)+,d1-d2/a0-a3/a6
  319. ;        rts
  320.  
  321. ; Stop to play the module
  322.  
  323. ;RemovePlayer:
  324. ;        movem.l d0-d1/a0-a1/a6,-(sp)
  325. ;        bsr.s   DisablePlayer
  326. ;        move.l  CiabBase,a6
  327. ;        lea     TimerInt,a1
  328. ;        moveq   #1,d0
  329. ;        jsr     _LVORemICRVector(a6)
  330. ;        bclr    #1,CIAAPRA
  331. ;        movem.l (sp)+,d0-d1/a0-a1/a6
  332. ;        rts
  333.  
  334. ;-------------- internal functions -----------------
  335.  
  336. ;InitInterrupt:
  337. ;        bsr.s   EnablePlayer
  338. ;        move.l  CiabBase,a6
  339. ;        lea     TimerInt,a1
  340. ;        moveq   #1,d0
  341. ;        jsr     _LVOAddICRVector(a6)
  342. ;        tst.l   d0
  343. ;        bne.s   InitInterruptEnd
  344. ;        move.b  CIABCRB,d0
  345. ;        and.b   #%10000000,d0
  346. ;        or.b    #1,d0
  347. ;        move.b  d0,CIABCRB
  348. ;        move.b  #$82,CIABICR
  349. ;        lea     TimerTable,a0
  350. ;        move.w  IsNTSC,d0
  351. ;        move.b  1(a0,d0),CIABTBLO
  352. ;        move.b  (a0,d0),CIABTBHI
  353. ;        moveq   #0,d0
  354. ;InitInterruptEnd:
  355. ;        rts
  356.  
  357. InitSampleAdr:
  358.         move.l  SongPointer,a1
  359.         lea     sng_Len(a1),a0
  360.         move.w  (a0)+,d0                ; d0 = songlen
  361.         subq.w  #1,d0
  362.         moveq   #0,d1
  363.         move.l  d1,d2
  364. SeekLastBlockLoop:
  365.         move.b  (a0)+,d2
  366.         cmp.b   d2,d1
  367.         bhi.s   NotLastBlock
  368.         move.b  d2,d1
  369. NotLastBlock:
  370.         dbra    d0,SeekLastBlockLoop
  371.         addq.w  #1,d1
  372.         moveq   #10,d0
  373.         lsl.l   d0,d1                   ; d1 = block size
  374.         lea     sng_Data(a1),a0
  375.         add.l   d1,a0                   ; a0 -> first sample
  376.         lea     sng_Instr0(a1),a2       ; a2 -> first instrument
  377.         lea     SampleAdrTable,a3
  378.         moveq   #MAXINSTR,d0
  379. InitAdrLoop:
  380.     clr.l    (a3)            ; clear pointer to prevent from illegal clear
  381.         moveq   #0,d1
  382.         move.w  instr_Len(a2),d1        ; len ?
  383.         beq.s   InitNextAdr
  384. InitThisAdr:
  385.         move.l  a0,(a3)
  386.         moveq   #0,d2
  387.         cmp.w   #1,instr_RLen(a2)       ; rlen
  388.         beq.s   GetSampleSize
  389.         move.w  instr_RLen(a2),d2
  390.         add.l   d2,d1
  391. GetSampleSize:
  392.         add.l   d1,d1
  393.         bclr    #0,instr_Start+3(a2)    ; align instr_Start on a word
  394.         add.l   instr_Start(a2),d1      ; Start
  395.         add.l   d1,a0                   ; a0 -> nextsample
  396. InitNextAdr:
  397.         addq.l  #4,a3
  398.         add.l   #SIZEOF_insdt,a2
  399.         dbra    d0,InitAdrLoop
  400.         rts
  401.  
  402. InitSamples:
  403.         lea     SampleAdrTable,a0
  404.         moveq   #MAXINSTR,d0
  405. InitSamplesLoop:
  406.         move.l  (a0)+,d1
  407.         beq.s   InitSamplesLoopEnd
  408.         move.l  d1,a1
  409.         moveq   #3,d2
  410. Clear4Bytes:
  411.         clr.b   (a1)+
  412.         dbra    d2,Clear4Bytes
  413. InitSamplesLoopEnd:
  414.         dbra    d0,InitSamplesLoop
  415.         rts
  416.  
  417.  
  418. DisablePlayer:
  419.         clr.w   AUD0LCH+AUDxVOL
  420.         clr.w   AUD1LCH+AUDxVOL
  421.         clr.w   AUD2LCH+AUDxVOL
  422.         clr.w   AUD3LCH+AUDxVOL
  423.         move.w  #$0f,DMACON
  424.         rts
  425.  
  426. EnablePlayer:
  427.         clr.w   AUD0LCH+AUDxVOL
  428.         clr.w   AUD1LCH+AUDxVOL
  429.         clr.w   AUD2LCH+AUDxVOL
  430.         clr.w   AUD3LCH+AUDxVOL
  431.         rts
  432.  
  433. TimerIntRoutine:
  434.         movem.l d1-d7/a0-a6,-(sp)
  435.         bsr.s   PlayRoutine
  436.         movem.l (sp)+,d1-d7/a0-a6
  437.         moveq   #0,d0
  438.         rts
  439.  
  440. PlayRoutine:
  441.         move.l  SongPointer,a6
  442.         move.w  8(a6),d0
  443.         addq.w  #1,PlayTimer
  444.         cmp.w   PlayTimer,d0            ; tempo == playtimer ?
  445.         bne.s   PlayEffects             ; no, play effects
  446.         clr.w   PlayTimer               ; yes, reset timer to zero
  447.         bra     PlaySound               ; play note
  448.  
  449. PlayEffects:
  450.         lea     ChannelData0,a0
  451.         lea     AUD0LCH,a1
  452.         moveq   #MAXTRACK-1,d3          ; 4 tracks
  453. PlayEffLoop:
  454.         move.w  (a0),d0
  455.         and.w   #$7ff,d0
  456.         cmp.w   #STOP,d0                ; note == STOP ?
  457.         beq.s   PlayEffLoopEnd
  458.         tst.b   ad_Info(a0)             ; effect value == 0 ?
  459.         beq.s   PlayEffLoopEnd
  460.         bsr.s   MakeEffects
  461. PlayEffLoopEnd:
  462.         add.l   #SIZEOF_ad,a0           ; a0 -> next channeldata
  463.         add.w   #SIZEOF_AUD,a1          ; a1 -> next audio register
  464.         dbra    d3,PlayEffLoop
  465.         rts
  466.  
  467. MakeEffects:
  468.         move.b  ad_Effet(a0),d0
  469.         beq.s   EffArpeggio
  470.         cmp.b   #PITCHUP,d0
  471.         beq.s   EffPitchUp
  472.         cmp.b   #PITCHDOWN,d0
  473.         beq.s   EffPitchDown
  474.         rts
  475.  
  476. EffArpeggio:
  477.         moveq   #0,d0
  478.         move.w  PlayTimer,d0
  479.         cmp.w   #1,d0
  480.         beq.s   EffArpOne
  481.         cmp.w   #2,d0
  482.         beq.s   EffArpTwo
  483.         cmp.w   #3,d0
  484.         beq.s   EffArpThree
  485.         cmp.w   #4,d0
  486.         beq.s   EffArpTwo
  487.         cmp.w   #5,d0
  488.         beq.s   EffArpOne
  489.         rts
  490.  
  491. EffArpOne:
  492.         move.b  ad_Info(a0),d0
  493.         lsr.b   #4,d0                   ; d0 = high nibble value
  494.         bra.s   EffArpSeek
  495. EffArpTwo:
  496.         move.b  ad_Info(a0),d0
  497.         and.b   #MASK_VAL,d0            ; d0 = low nibble value
  498.         bra.s   EffArpSeek
  499. EffArpThree:
  500.         move.w  ad_ArpPer(a0),d2        ; d2 = normal period
  501.         bra.s   EffArpFound
  502. EffArpSeek:
  503.         add.w   d0,d0                   ; d0 = offset notetable
  504.         move.w  ad_ArpPer(a0),d1        ; d1 = normal period
  505.         lea     NoteTable,a2
  506. EffArpLoop:
  507.         move.w  (a2,d0.w),d2            ; d2 = new period
  508.         cmp.w   (a2)+,d1                ; (a2) == normal period
  509.         bne.s   EffArpLoop
  510. EffArpFound:
  511.         move.w  d2,AUDxPER(a1)
  512.         rts
  513.  
  514. EffPitchUp:
  515.         moveq   #0,d0
  516.         move.b  ad_Info(a0),d0          ; d0 = effect value
  517.         sub.w   d0,ad_PitchPer(a0)
  518.         cmp.w   #SI5,ad_PitchPer(a0)    ; less than lowest period ?
  519.         bpl.s   EffPitchOK
  520.         move.w  #SI5,ad_PitchPer(a0)
  521.         bra.s   EffPitchOK
  522. EffPitchDown:
  523.         moveq   #0,d0
  524.         move.b  ad_Info(a0),d0
  525.         add.w   d0,ad_PitchPer(a0)
  526.         cmp.w   #DO2,ad_PitchPer(a0)    ; more than highest period ?
  527.         bmi.s   EffPitchOK
  528.         move.w  #DO2,ad_PitchPer(a0)
  529. EffPitchOK:
  530.         move.w  ad_PitchPer(a0),AUDxPER(a1)
  531.         rts
  532.  
  533. PlaySound:
  534.         lea     sng_Data(a6),a0
  535.         lea     sng_Seq(a6),a1
  536.         move.w  CurrentPos,d0
  537.         move.w  d0,NewPosJump
  538.         moveq   #0,d1
  539.         move.b  0(a1,d0.w),d1           ; d1 = block number
  540.         moveq   #10,d0
  541.         lsl.l   d0,d1
  542.         add.l   OffsetBlock,d1          ; d1 = offset into block data
  543.         clr.w   AudioDMA
  544.  
  545.         lea     AUD0LCH,a3
  546.         lea     ChannelData0,a4
  547.         moveq   #MAXTRACK-1,d7          ; 4 tracks
  548. PlayLoop:
  549.         bsr     PlayInstr
  550.         add.w   #SIZEOF_AUD,a3
  551.         add.l   #SIZEOF_ad,a4
  552.         dbra    d7,PlayLoop
  553.  
  554.         move.w  AudioDMA,d0             ; start audio DMA
  555.         or.w    #DMASET,d0
  556.         move.w  d0,DMACON
  557.  
  558.     bsr    DMAwait            ; !!!
  559.  
  560. ;        move.b  CIABCRA,d1              ; buh : busy waiting with cia timer !!!
  561. ;        move.b  d1,d0
  562. ;        and.b   #%11000000,d0
  563. ;        or.b    #%00001000,d0
  564. ;        move.b  d0,CIABCRA
  565. ;        move.b  #$2f,CIABTALO
  566. ;        move.b  #1,CIABTAHI
  567. ;PlayDelay1:
  568. ;        btst.b  #0,CIABCRA
  569. ;        bne.s   PlayDelay1
  570. ;        move.b  d1,CIABCRA
  571. ;        move.b  #%00000001,CIABICR
  572.  
  573.         lea     ChannelData0,a0         ; set new value into audio registers
  574.         lea     AUD0LCH,a1
  575.         moveq   #MAXTRACK-1,d0
  576. SetNewValue:
  577.         move.l  ad_RepAdr(a0),(a1)
  578.         move.w  ad_RepLen(a0),AUDxLEN(a1)
  579.         add.l   #SIZEOF_ad,a0
  580.         add.w   #SIZEOF_AUD,a1
  581.         dbra    d0,SetNewValue
  582.         cmp.l   #BLOCKSIZE-NEXTLINE,OffsetBlock  ; end of block ?
  583.         beq.s   ChangePosition
  584.         add.l   #NEXTLINE,OffsetBlock   ; modif. offsetblock
  585.         tst.w   BreakStatus             ; jump or break ?
  586.         beq.s   PlaySoundEnd
  587.         clr.w   BreakStatus
  588. ChangePosition:
  589.         clr.l   OffsetBlock             ; offset block = 0
  590.         move.w  NewPosJump,CurrentPos
  591.         addq.w  #1,CurrentPos           ; new position
  592.         move.w  sng_Len(a6),d0
  593.         move.w  CurrentPos,d1
  594.         cmp.w   d0,d1                   ; end of song ?
  595.         bne.s   PlaySoundEnd
  596.         clr.w   CurrentPos              ; position = 0
  597. PlaySoundEnd:
  598.         rts
  599.  
  600. PlayInstr:
  601.         lea     sng_Instr0(a6),a2
  602.         move.l  (a0,d1.l),ad_SampPer(a4)
  603.         addq.l  #NEXTTRACK,d1
  604.         moveq   #0,d0
  605.         move.b  ad_SampPer(a4),d0
  606.         lsr.b   #3,d0                   ; d0 = instrument number
  607.         tst.b   d0                      ; d0 == 0 ?
  608.         beq.s   NoSampleChange
  609.  
  610.         lea     SampleAdrTable,a5
  611.         subq.b  #1,d0
  612.         move.l  d0,d3
  613.         lsl.w   #2,d0                   ; d0 = SampleAdrTable offset
  614.         mulu    #SIZEOF_insdt,d3
  615.         add.l   #instr_Start,d3
  616.         add.l   d3,a2                   ; a2 -> Start InstrData
  617.         move.l  (a5,d0.w),d4
  618.         add.l   (a2)+,d4                ; Start
  619.         move.l  d4,ad_SmpAdr(a4)
  620.         beq.s   NoSampleChange
  621.         move.w  (a2)+,ad_SmpLen(a4)     ; Len
  622.         move.l  (a2)+,d5                ; RStart
  623.         move.w  (a2)+,d2                ; RLen
  624.         bne.s   SetRepeat
  625.         moveq   #1,d2
  626.         moveq   #0,d5
  627. SetRepeat:
  628.         move.w  d2,ad_RepLen(a4)
  629.         add.l   ad_SmpAdr(a4),d5
  630.         move.l  d5,ad_RepAdr(a4)
  631.         move.w  (a2),ad_Volume(a4)      ; Volume
  632. NoSampleChange:
  633.         move.w  ad_SampPer(a4),d6
  634.         and.w   #$7ff,d6                ; note == 0 ?
  635.         beq.s   TestEffects
  636.         move.w  d6,ad_ArpPer(a4)
  637.         move.w  ad_DMABit(a4),d0
  638.         move.w  d0,DMACON               ; cut DMA audio for this track
  639.  
  640.     bsr    DMAwait            ; !!!
  641.  
  642. ;        move.b  CIABCRA,d2              ; wait loop
  643. ;        move.b  d2,d3
  644. ;        and.b   #%11000000,d3
  645. ;        or.b    #%00001000,d3
  646. ;        move.b  d3,CIABCRA
  647. ;        move.b  #$2f,CIABTALO
  648. ;        move.b  #1,CIABTAHI
  649. ;PlayDelay2:
  650. ;        btst.b  #0,CIABCRA
  651. ;        bne.s   PlayDelay2
  652. ;        move.b  d2,CIABCRA
  653. ;        move.b  #%00000001,CIABICR
  654.  
  655.         cmp.w   #STOP,d6                ; note == 'OFF' ?
  656.         bne.s   SetPlayRegs
  657.         clr.w   AUDxVOL(a3)             ; set audio volume to 0
  658.         or.w    d0,AudioDMA
  659.         rts
  660.  
  661. DMAwait:moveq    #4,d3
  662. DMAwai2:move.b    $dff006,d2
  663. DMAwai3:cmp.b    $dff006,d2
  664.     beq.s    DMAwai3
  665.     dbf    d3,DMAwai2
  666.     rts
  667.  
  668. SetPlayRegs:
  669.         move.l  ad_SmpAdr(a4),(a3)      ; sample address == NULL ?
  670.         beq.s   TestEffects
  671.         move.w  ad_SmpLen(a4),AUDxLEN(a3)
  672.         move.w  d6,AUDxPER(a3)
  673.         or.w    d0,AudioDMA
  674.         move.w  d6,ad_PitchPer(a4)
  675. TestEffects:
  676.         move.b  ad_Effet(a4),d0         ; d0 = effect
  677.         bsr.s   EffVolume
  678.         tst.b   d0
  679.         beq.s   TestEffectsEnd
  680. ;        cmp.b   #FILTER,d0
  681. ;        beq.s   EffFilter
  682.         cmp.b   #MASTERVOL,d0
  683.         beq.s   EffMaster
  684.         cmp.b   #TEMPO,d0
  685.         beq.s   EffSpeed
  686.         cmp.b   #JUMP,d0
  687.         beq.s   EffJump
  688. TestEffectsEnd:
  689.         rts
  690.  
  691. EffVolume:                              ; modify volume
  692.         cmp.w   #VOLUME,d0
  693.         bne.s   UseInstrVol
  694.         moveq   #0,d2
  695.         move.b  ad_Info(a4),d2          ; d0 = new volume
  696.         bra.s   SetInstrVol
  697. UseInstrVol:
  698.         tst.w   d6
  699.         beq.s   EffVolumeEnd
  700.         move.w  ad_Volume(a4),d2
  701. SetInstrVol:
  702.         sub.w   MasterVolume,d2         ; new volume - master >= 0
  703.         bge.s   SetVolumeReg
  704.         moveq   #0,d2                   ; new volume = 0
  705. SetVolumeReg:
  706.         move.w  d2,AUDxVOL(a3)          ; new volume into audio reg
  707. EffVolumeEnd:
  708.         rts
  709.  
  710. EffMaster:                              ; modify master volume
  711.         moveq   #MAX_VOL,d2
  712.         move.b  ad_Info(a4),d0
  713.         sub.b   d0,d2
  714.         blt.s   EffMasterEnd
  715.         move.b  d2,MasterVolume+1
  716. EffMasterEnd:
  717.         rts
  718.  
  719. EffSpeed:                               ; modify tempo
  720.         move.b  ad_Info(a4),d0
  721.         beq.s   EffSpeedEnd
  722.         clr.w   PlayTimer
  723.         move.b  d0,sng_Tempo+1(a6)
  724. EffSpeedEnd:
  725.         rts
  726.  
  727. EffJump:                                ; jump or break
  728.         move.w  #1,BreakStatus
  729.         move.b  ad_Info(a4),d0
  730.         cmp.b   #BREAK,d0
  731.         beq.s   EffBreak
  732.         subq.b  #2,d0
  733.         ext.w   d0
  734.         move.w  d0,NewPosJump
  735.         rts
  736. EffBreak:
  737.         move.w  CurrentPos,NewPosJump
  738.         rts
  739.  
  740. ;EffFilter:                              ; filter on/off
  741. ;        move.b  ad_Info(a4),d0
  742. ;        bne.s   SetFilter
  743. ;        bset    #1,CIAAPRA
  744. ;        rts
  745. ;SetFilter:
  746. ;        bclr    #1,CIAAPRA
  747. ;        rts
  748.  
  749.         DSEG
  750.  
  751. ;CiabBase:       dc.l    0
  752. ;IsNTSC:         dc.w    0
  753.  
  754. ;CiabName:       dc.b    'ciab.resource',0
  755. ;TimerIntName:   dc.b    'DSS Tracker Player',0
  756. ;                cnop    0,2
  757.  
  758. ;TimerInt:
  759. ;        dc.l  0                 ; Interrupt.is_Node.ln_Succ
  760. ;        dc.l  0                 ; Interrupt.is_Node.ln_Pred
  761. ;        dc.b  2                 ; Interrupt.is_Node.ln_Type = NT_INTERRUPT
  762. ;        dc.b  -10               ; Interrupt.is_Node.ln_Pri
  763. ;        dc.l  TimerIntName      ; Interrupt.is_Node.ln_Name
  764. ;        dc.l  0                 ; Interrupt.is_Data
  765. ;        dc.l  TimerIntRoutine   ; Interrupt.is_Code
  766.  
  767.  
  768. PlayOn:         dc.w    0
  769. PlayTimer:      dc.w    0
  770. CurrentPos:     dc.w    0
  771. OffsetBlock:    dc.l    0
  772. AudioDMA:       dc.w    0
  773. MasterVolume:   dc.w    0
  774. BreakStatus:    dc.w    0
  775. NewPosJump:     dc.w    0
  776.  
  777. ChannelData0:
  778.         dc.w    0               ; Period                0
  779.         dc.w    0               ; Sample+Info           2
  780.         dc.w    0               ; Volume                4
  781.         dc.l    0               ; Sample address        6
  782.         dc.w    0               ; Sample length        10
  783.         dc.l    0               ; Repeat address       12
  784.         dc.w    0               ; Repeat length        16
  785.         dc.w    0               ; Shazam period        18
  786.         dc.w    1               ; DMA bit              20
  787.         dc.w    0               ; Pitch  period        22
  788. ChannelData1:
  789.         ds.w    10
  790.         dc.w    2
  791.         dc.w    0
  792. ChannelData2:
  793.         ds.w    10
  794.         dc.w    4
  795.         dc.w    0
  796. ChannelData3:
  797.         ds.w    10
  798.         dc.w    8
  799.         dc.w    0
  800.  
  801.         dc.w    1712
  802. NoteTable:
  803.         dc.w    1712,1616,1524,1440,1356,1280,1208,1140,1076,1016,960,906
  804.         dc.w    856,808,762,720,678,640,604,570,538,508,480,453
  805.         dc.w    428,404,381,360,339,320,302,285,269,254,240,226
  806.         dc.w    214,202,190,180,170,160,151,143,135,127,120,113
  807.         dc.w    113,113,113,113,113,113,113,113,113,113,113,113
  808.         dc.w    113,113,113,113,113,113,113,113,113,113,113,113
  809.         dc.w    113,113,113,113,113,113
  810.  
  811. SampleAdrTable: ds.l    31
  812.  
  813. ;TimerTable:     dc.w    14187,14318
  814.  
  815. SongPointer:    dc.l    0               ; address of Module in CHIP memory
  816.  
  817.